import 'dart:io';

import 'package:dio/adapter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../utils/utils.dart';
import '../values/values.dart';

extension NumExtension on num {
  SizedBox get vGap => SizedBox(width: w);

  SizedBox get hGap => SizedBox(height: h);

  BorderRadiusGeometry get radius => BorderRadius.circular(r);
}

extension RequestExtension on HttpUtil {
  /// 设置环境变量，指示应用使用Charles作为代理
  void setProxy() {
    if (GetPlatform.isAndroid & PROXY_ENABLE) {
      (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
          (HttpClient client) {
        client.badCertificateCallback = (cert, host, port) {
          return true;
        };
        client.findProxy = (uri) {
          return "PROXY $PROXY_IP:$PROXY_PORT";
        };
        return null;
      };
    }
  }
}
